package com.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dao.UserinfoDAO;
import com.pojo.UserinfoPOJO;
import com.util.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.security.NoSuchAlgorithmException;

import static com.util.MD5Util.string2MD5;

@SuppressWarnings("ALL")
@Service
public class UserinfoService {

    @Autowired
    private UserinfoDAO userinfoDAO;

    /**
     *   根据账号密码登录
     * @param user  账号
     * @param pwd   密码
     * @return
     * @throws NoSuchAlgorithmException
     */

    public UserinfoPOJO login(String user, String pwd) throws NoSuchAlgorithmException {
        QueryWrapper q = new QueryWrapper();
        if(user!=null && user.trim().length()>0){
            q.eq("user_name",user);
        }
        if(pwd!=null && pwd.trim().length()>0){
            String password= MD5Util.encryptionPassword(pwd);
            q.eq("user_password",password);
        }
        return  userinfoDAO.selectOne(q);
    }

}

